//------------------------------------------------
// cGame_paint.h
//------------------------------------------------

// static Graphics s_gBackBuffer;
// static Image s_imgBackBuffer;
#define BUTTON_OK_WIDTH 31
#define BUTTON_OK_HEIGHT 25
#define BUTTON_BACK_WIDTH 22
#define BUTTON_BACK_HEIGHT 21

void GamePaint()
{
	try
	{
		StateMachine_Paint();
		PaintSoftkey(s_gBackBuffer);
	}
	catch(Exception ex){}
}

static void DrawMenu(Graphics g, int[] _menu, boolean isDrawMenuTitle)
{
	int y = _menu_y;
	int w = 0;
	int dx = 0;
	if(isDrawMenuTitle)
	{
		w=GetStringWidth(GetString(_menu[0]));
		DrawString(g, GetString(_menu[0]), (s_iWidth-w)/2, _menu_title_y);
	}
	for(int i=0; i<_menu.length-1; i++)
	{
		if(i == _menu_item_focused)
			s_sprMenu.PaintModule(g, LIGHT_BUTTON, _menu_x, y);
		else
			s_sprMenu.PaintModule(g, DARK_BUTTON, _menu_x, y);
		w=GetStringWidth(GetString(_menu[i+1]));
		dx = MENU_WIDTH - w;
		DrawString(g, GetString(_menu[i+1]), _menu_x + dx/2, y+6);
		y += (MENU_HEIGHT + _menu_spacing);
	}
}

static void PaintSoftkey(Graphics g)
{
	if(softkeyLeft)
	{
		s_sprMenu.PaintModule(g, BUTTON_OK, 0, s_iHeight - BUTTON_OK_HEIGHT);
	}
	if(softkeyRight)
	{
		s_sprMenu.PaintModule(g, BUTTON_BACK, s_iWidth - BUTTON_BACK_WIDTH, s_iHeight - BUTTON_BACK_HEIGHT);
	}
}

static void PaintDialogConfirm(Graphics g, int[] _menu_dialog, boolean isPaintDialogTitle)
{
	// g.setClip(_dialog_x, _dialog_y, _dialog_width, _dialog_height);
	g.setColor(92, 255, 0);
	g.fillRect(_dialog_x, _dialog_y, _dialog_width, _dialog_height);
	// g.fillRect(0,0,240,320);
	g.setColor(255, 0, 0);
	g.fillRect(_dialog_x, _dialog_y, _dialog_width, 4);	
	g.fillRect(_dialog_x, _dialog_y + _dialog_height - 1, _dialog_width, 4);
	
	int y = _menu_y;
	int w, dx;
	if(isPaintDialogTitle)
	{
		w=GetStringWidth(GetString(_menu_dialog[0]));
		DrawString(g, GetString(_menu_dialog[0]), (s_iWidth-w)/2, _dialog_y + 10);
	}
	
	for(int i = 0; i<_menu_dialog.length-1; i++)
	{
		if(i == _dialog_item_focused)
			s_sprMenu.PaintModule(g, LIGHT_BUTTON, _menu_x, y);
		else
			s_sprMenu.PaintModule(g, DARK_BUTTON, _menu_x, y);
		w=GetStringWidth(GetString(_menu_dialog[i+1]));
		dx = s_iWidth - w;
		DrawString(g, GetString(_menu_dialog[i+1]), dx/2, y+6);
		y += (MENU_HEIGHT + _menu_spacing);
	}
}